home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8312 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.0 KB

  1. Path: news.eden.com!usenet
  2. From: Shane Sadler <nexus@eden.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: [Q] functions returning structures
  5. Date: Sat, 02 Mar 1996 20:53:54 -0700
  6. Organization: Eden Matrix Services
  7. Message-ID: <313917D2.78CA51AB@eden.com>
  8. References: <4hasjj$opf@decaxp.harvard.edu>
  9. NNTP-Posting-Host: net-4-139.austin.eden.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (X11; I; Linux 1.2.8 i586)
  14.  
  15. Carlo Martino wrote:
  16. [snip]
  17. > This work fine in SunOS.  But when I ported this morning to HP-UX, the
  18. > value assigned to "new_color" was always screwy.  I walked through it
  19. > in gdb, and the values within "get_color" were precisely what they ought
  20. > to be; it was only the returned structure that was mess up.
  21. > So I changed things:
  22. >         RGB*    get_color(      VECTOR          position );
  23. > Which requires an extra free after I'm done with the values referenced by
  24. > the returned pointer.  Not to mention the fact that screwing around with
  25. > the pointers, when all I real want is the values, is considerably less
  26. > elegant.
  27. > What was going wrong?  Is there a way to return structures without putting
  28. > them on the heap?  When am I at risk for structures to become corrupt and
  29. > when am I OK?
  30.  
  31. Carlos,
  32.  
  33. I always thought pointers were *more* elegant than passing the whole
  34. structure to a function...oh well. :)
  35.  
  36. The HP-UX compiler is notoriously anti-ANSI during a normal compile (and
  37. according to K&R1, C has no provisions for passing structures to
  38. functions), but you should have an ANSI compile mode. You'll have to
  39. look it up in your man pages because I don't remember what the flag is
  40. (-A?). Try compiling your code using the ANSI mode and see what happens. 
  41.  
  42. If that doesn't work, you can try declaring your structure as global and
  43. accessing it that way. It's inelegant, but no more so than what you're
  44. trying to do.
  45.  
  46. Hope that helps you.
  47.  
  48. -- Shane
  49. ===================================================================
  50. S. M. Sadler
  51. e-mail: nexus@eden.com
  52. Web: http://www.eden.com/~nexus
  53.